Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing scalar shape handling: treat (1,) as vectors #4214

Merged
merged 22 commits into from
Dec 20, 2020

Conversation

michaelosthege
Copy link
Member

@michaelosthege michaelosthege commented Nov 9, 2020

Breaking Changes

  • From now on () is the only scalar shape. (1,) will become vector of length 1

New Shape Examples

  • Normal("n", shape=None) is the same as the default Normal("n"). Here it is up to the distribution (most will default to ())
  • shape=() explicitly specifies scalar shape
  • shape=0 or shape=(0,) is up for discussion (see below)
  • shape=1 is the same as shape=(1,) is a length 1 vector

Open ToDos

  • This blows up hundreds of a few tests. They must be fixed.
  • Make sure to raise a VelueError when a user passes shape=(0,) / shape=0 to a distribution
  • size=(0,)/size=0 to .random() remains allowed - because numpy also allows it on the random number generator
  • Check out the RandomWalk distributions. While the tests cover shapes, they don't necessarily catch problems like GaussianRandomWalk prior predictive is broken #3962 (they look fine, but most don't have a .random() implementation. See .random() methods missing from some timeseries distributions #4337 )
  • release notes
  • re-running relevant notebooks (oh dear!) Let's do this on a separate PR

+ by using more pytest.mark.parametrize, the overall number of overall tests increases, but the result should be easier to diagnose
+ an informative assert error message was added
@AlexAndorra
Copy link
Contributor

Thanks for taking the initiative @michaelosthege !
First comment: "re-running relevant notebooks (oh dear!)" --> 🤣

@michaelosthege
Copy link
Member Author

michaelosthege commented Nov 10, 2020

I think I ran into the same problem as @StephenHogg in #4211

EDIT: I removed the traceback, because it's now documented in #4219

I'm on a quite recent Theano-PyMC master branch (4249a0). (Maybe you are too, @StephenHogg?)

@brandonwillard assuming that this is indeed due to a change in Theano-PyMC, do you know about this issue already? Any hints?

@codecov
Copy link

codecov bot commented Nov 10, 2020

Codecov Report

Merging #4214 (0a5b04b) into master (34447a7) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4214      +/-   ##
==========================================
+ Coverage   87.95%   87.97%   +0.02%     
==========================================
  Files          88       88              
  Lines       14499    14483      -16     
==========================================
- Hits        12752    12741      -11     
+ Misses       1747     1742       -5     
Impacted Files Coverage Δ
pymc3/distributions/mixture.py 88.69% <ø> (+0.26%) ⬆️
pymc3/distributions/posterior_predictive.py 89.23% <ø> (-0.07%) ⬇️
pymc3/distributions/discrete.py 95.82% <100.00%> (+0.59%) ⬆️
pymc3/distributions/distribution.py 95.40% <100.00%> (+0.09%) ⬆️
pymc3/distributions/multivariate.py 82.90% <0.00%> (+0.14%) ⬆️
pymc3/math.py 68.64% <0.00%> (+0.17%) ⬆️

@StephenHogg
Copy link
Contributor

As far as theano-pymc goes, here's what pip freeze has to say:

Theano==1.0.5
Theano-PyMC==1.0.10

The error looks the same, yes.

@michaelosthege michaelosthege marked this pull request as ready for review November 10, 2020 12:25
@brandonwillard
Copy link
Contributor

The key line is here:

pymc3\model.py:1800: in __init__
    self.tag.test_value = theano.compile.view_op(data).tag.test_value

We recently introduced a change to Theano's test value handling that validates the test values up front. The fix requires that the PyMC3-assigned test values be cast to the appropriate types (e.g. theano.compile.view_op(data).tag.test_value needs to be changed to something like theano.compile.view_op(data).tag.test_value.astype(self.dtype)).

RELEASE-NOTES.md Outdated Show resolved Hide resolved
Copy link
Contributor

@lucianopaz lucianopaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes here look fine.

However, i know that the MixtureSameFamily also does a check for size=1 that should be removed here. I imagine that other "meta distributions" like the Mixture and DensityDist do the something similar. Could you check those too?

@michaelosthege
Copy link
Member Author

@lucianopaz thanks. Only in MixtureSameFamily I found the corresponding lines.

RELEASE-NOTES.md Outdated Show resolved Hide resolved
@twiecki
Copy link
Member

twiecki commented Dec 20, 2020

You know it's a good PR when:
Uploading image.png…

@twiecki twiecki merged commit e1af7c9 into pymc-devs:master Dec 20, 2020
@twiecki
Copy link
Member

twiecki commented Dec 20, 2020

Thanks!

@mjhajharia
Copy link
Member

can I work on this?

@ricardoV94
Copy link
Member

can I work on this?

Did you mean this: #3896

@mjhajharia
Copy link
Member

mjhajharia commented Mar 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants